import pytest
import time
from selenium import webdriver
from lianxi630.common import  *
from selenium.webdriver.common.by import By

@pytest.fixture(scope='function')
def driver():
    driver=webdriver.Edge()
    driver.maximize_window()
    driver.get('http://10.59.9.14:7003/')

    yield driver
    driver.quit()

class Test_case():
    @pytest.mark.parametrize('test_case',json_data())
    def test_login(self,driver,test_case):
        driver.find_element(By.LINK_TEXT, '登录').click()
        time.sleep(2)
        # 将json中的username和password放到我们编写的测试用例里面的用户名和密码上
        driver.find_element(By.NAME, 'username').send_keys(test_case['username'])
        driver.find_element(By.NAME, 'password').send_keys(test_case['password'])
        time.sleep(10)
        driver.find_element(By.CLASS_NAME, 'finish-btn').click()
        time.sleep(5)
        if test_case['case_id'] == 'case_001':
            dy = driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').text
            print('登录成功后断言:', dy)
        else:
            dy = driver.find_element(By.XPATH, '/html/body/div[4]/div/div[1]/div[1]/span[1]').text
            print('登录失败后断言', dy)
        driver.quit()

